package com.youxue.teachin.set.main.binder;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.ali.music.multiimageselector.MultiImageSelectorUtils;
import com.library.uiframework.widget.imageview.NetworkImageView;
import com.library.xtype.DefaultNuwaItemBinder;
import com.youxue.teachin.R;
import com.youxue.teachin.set.main.vo.UserIconVO;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-06 13:55
 * @version: 9.1.0
 */
public class UserIConBinder extends DefaultNuwaItemBinder<UserIconVO> implements OnClickListener{
    private View mRootView;
    private NetworkImageView mUserIcon;
    private ImageView mIconEdit;
    UserIconVO mUserIconVO;

    @Override
    public View onCreateView(View convertView, ViewGroup parent, LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.set_main_user_icon_binder, parent, false);
        initView(view);
        return view;
    }

    @Override
    public void onBindView(int positionOfFeeds, View convertView, ViewGroup parent, UserIconVO vo) {
        mUserIconVO = vo;
        mUserIcon.setPlaceholderImage(R.drawable.default_avatar)
            .setUrl(vo.mIcon);
        mIconEdit.setTag(vo);
    }

    @Override
    public void setOnClickListener(OnClickListener listener) {
        super.setOnClickListener(listener);
        mIconEdit.setOnClickListener(listener);
    }

    private void initView(View rootView) {
        mRootView = rootView;
        mUserIcon = (NetworkImageView)rootView.findViewById(R.id.user_icon);
        mIconEdit = (ImageView)rootView.findViewById(R.id.icon_edit);

        mUserIcon.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        ArrayList<String> list = new ArrayList(0);
        list.add(mUserIconVO.mIcon);
        MultiImageSelectorUtils.previewPictures(v.getContext(), list, 0);
    }
}
